package com.jsy.common.util.bytecode;

import org.objectweb.asm.*;

import java.io.IOException;

public class RemoveLineNumber {
    public static void main(String[] args) throws IOException {
        ClassReader cr = new ClassReader("ClassName"); // 替换为要修改的类名
        ClassWriter cw = new ClassWriter(cr, 0);
        ClassVisitor cv = new RemoveLineNumberAdapter(cw);
        cr.accept(cv, 0);
 
        byte[] data = cw.toByteArray();
        // 将字节码写入文件或进行其他操作
    }
 
    static class RemoveLineNumberAdapter extends ClassVisitor {
        public RemoveLineNumberAdapter(ClassVisitor cv) {
            super(Opcodes.ASM9, cv);
        }
 
        @Override
        public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
            MethodVisitor mv = cv.visitMethod(access, name, descriptor, signature, exceptions);
            return mv == null ? null : new RemoveLineNumberMethodAdapter(mv);
        }
    }
 
    static class RemoveLineNumberMethodAdapter extends MethodVisitor {
        public RemoveLineNumberMethodAdapter(MethodVisitor mv) {
            super(Opcodes.ASM9, mv);
        }
 
        @Override
        public void visitLineNumber(int line, Label start) {
            // 删除指定行，这里line为指定行号
            // 不调用 super.visitLineNumber，直接跳过写入行号信息
        }
    }
}